﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Assist
{
	public class YJKComboBox : System.Windows.Forms.ComboBox
	{
		protected override void OnDropDown(EventArgs e)
		{
			base.OnDropDown(e);
			this.AdjustComboBoxDropDownListWidth();
		}

		private void AdjustComboBoxDropDownListWidth()
		{
			Graphics graphics = null;
			try
			{
				int num = base.Width;
				graphics = base.CreateGraphics();
				Font font = this.Font;
				int num2 = (base.Items.Count > base.MaxDropDownItems) ? SystemInformation.VerticalScrollBarWidth : 0;
				foreach (object obj in base.Items)
				{
					bool flag = obj != null;
					if (flag)
					{
						int num3 = (int)graphics.MeasureString(obj.ToString().Trim(), font).Width + num2;
						bool flag2 = num < num3;
						if (flag2)
						{
							num = num3;
						}
					}
				}
				base.DropDownWidth = num;
			}
			catch
			{
			}
			finally
			{
				bool flag3 = graphics != null;
				if (flag3)
				{
					graphics.Dispose();
				}
			}
		}
	}
}
